package org.eclipse.unofficial.flexitabs.adapted;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
import org.eclipse.unofficial.flexitabs.internal.PartPane;
import org.eclipse.unofficial.flexitabs.internal.PartStack;
import org.eclipse.unofficial.flexitabs.internal.PresentablePart;
import org.eclipse.unofficial.flexitabs.internal.WorkbenchPage;

import org2.eclipse.ui.internal.ILayoutContainer;
import org2.eclipse.ui.internal.LayoutPart;
import org2.eclipse.ui.internal.ViewStack;
import org2.eclipse.ui.presentations.IPresentablePart;


@SuppressWarnings("restriction")
public class FlexiStack extends PartStack {
	//for code-browsing only;
	private ViewStack stack;
	
	public FlexiStack(WorkbenchPage page) {
		super(PresentationFactoryUtil.ROLE_EDITOR);
	}

	@Override
	protected boolean isMoveable(IPresentablePart part) {
		return true;
	}

	@Override
	protected void addSystemActions(IMenuManager menuManager) {
		//don't think we need any of this
	}

	@Override
	protected boolean supportsState(int newState) {
		return true;
	}

	@Override
	protected boolean canMoveFolder() {
		return true;
	}

	@Override
	protected void derefPart(LayoutPart part) {
		ILayoutContainer oldContainer = part.getContainer();
		
		if (oldContainer == null) {
			return;
		}
		oldContainer.remove(part);
		LayoutPart[] children = oldContainer.getChildren();
		if (children == null || children.length == 0) {
			if (oldContainer instanceof LayoutPart) {
				LayoutPart parent = (LayoutPart) oldContainer;
				ILayoutContainer parentContainer = parent.getContainer();
				if (parentContainer != null) {
					parentContainer.remove(parent);
					parent.dispose();
				}
			}
		}
	}

	@Override
	protected boolean allowsDrop(PartPane part) {
		return part instanceof FlexiPane;
	}

	@Override
	protected void updateActions(PresentablePart current) {
		//don't think we need any of this...
	}
}
